import gulp, { series } from 'gulp';
import log from 'fancy-log';
import chalk from 'chalk';
import ts from 'gulp-typescript';
import del from 'del';

const ProjectConfig = {
    baseOutputPath: 'dist',
};

function clean(done) {
    log(chalk.green(`Clean Output...`));
    del(['dist']).then(() => done());
}

function copyTemplates() {
    log(chalk.green(`Copy Templates...`));
    return gulp.src('template/**/*.njk').pipe(gulp.dest(`${ProjectConfig.baseOutputPath}/template`));
}

function buildSrcScripts() {
    log(chalk.green(`Build Scripts...`));

    const tsProject = ts.createProject('tsconfig.json');

    return gulp
        .src('src/**/*.{ts,js}', { base: 'src' })
        .pipe(tsProject())
        .pipe(gulp.dest(ProjectConfig.baseOutputPath));
}

module.exports = {
    build: series(clean, buildSrcScripts, copyTemplates),
};
